// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import App from './App';
import App2 from './App2';
import VueRouter from 'vue-router';
import RouterConfig from './router';
import iView from 'iview';
import 'iview/dist/styles/iview.css';
import './assets/theme/styles.less';
import './assets/style.css'
import VueHighlightJS from 'vue-highlightjs'
import store from './vuex/store';
import { fetch, post } from './axios/http';
import { getUrlKey } from './utils/tools';
import Vuex from 'vuex';
import VueResource from 'vue-resource'


// Tell Vue.js to use vue-highlightjs
Vue.use(Vuex)
Vue.use(VueHighlightJS)
Vue.use(VueRouter);
Vue.use(iView);
Vue.use(VueResource);

//Vue.http.options.root = "http://127.0.0.1:8089/"
//Vue.http.options.emulateJSON = true
//Vue.http.options.credientials = true
Vue.prototype.$fetch = fetch
Vue.prototype.$post = post
Vue.prototype.$getUrlKey = getUrlKey
Vue.prototype.$loading = function (show) {
    Vue.nextTick(function () {
        store.commit('FETCH_LOADING', show)
    })
}
Vue.config.productionTip = false

// The routing configuration
const router = new VueRouter(RouterConfig);


router.beforeEach((to, from, next) => {
    iView.LoadingBar.start();
    console.log('user is==',store.getters.getUser)
    console.log('user is **==',store.getters.getUser.accountId)
    let isLogin = store.getters.getUser.accountId;
    if (!isLogin) {
        if (to.path !== '/') {
            return next({path: '/'});
        }else {
            next();
        }
    }else {
        if (to.path === '/') {
            return next({path: '/index'});
        }
        next();
    }
    
});

router.afterEach(route => {
    iView.LoadingBar.finish();
});

/* eslint-disable no-new */
export let app = new Vue({
    el:'#app',
    router,
    store,
    render:c=>c(App2)
})

// export let app = new Vue({
//     el: '#app',
//     router,
//     store,
//     render:c=>c(App)
//     // template: '<App/>',
//     // components: {
//     //     App
//     // }
// })


